/**
 * 
 */
package com.android.weibogo;

import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

/**
 * @author xiang.jianhua
 *
 */
public abstract class WeiboAdapter extends BaseAdapter {
	
	private ListView mView;
	
	private List<WeiboInfo> wbList;

	/**
	 * @return the wbList
	 */
	public List<WeiboInfo> getWbList() {
		return wbList;
	}

	/**
	 * @param wbList the wbList to set
	 */
	public void setWbList(List<WeiboInfo> wbList) {
		this.wbList = wbList;
	}

	/**
	 * @param mView
	 */
	public WeiboAdapter(ListView mView) {
		super();
		this.mView = mView;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		//the last item is for showing next page
		if(wbList.size() > 0)
			return wbList.size() + 1;
		else
			return 0;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		if(position < wbList.size())
			return wbList.get(position);
		else
			return null;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		return position;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void refresh(boolean retainLastPos){
		int lastVisiblePos = mView.getLastVisiblePosition();
		mView.setAdapter(this);
		if(retainLastPos && mView.getCount() > lastVisiblePos){
			mView.setSelection(lastVisiblePos);
		}
	}

}
